﻿using System;
using System.Globalization;
using System.IO;
using System.Windows.Data;

namespace Poet.Converters
{
    public class TitleConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var title = value as string;
            if (title == null)
                return null;

            var extension = Path.GetExtension(title) ?? string.Empty;
            extension = extension.Length < 7 ? extension : extension.Substring(0, 3) + "...";
            var fileName = Path.GetFileNameWithoutExtension(title) ?? string.Empty;
            return fileName.Length < 20 ? fileName + extension : fileName.Substring(0, 16) + "..." + extension;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
